package com.gec.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gec.model.system.ITripHotel;
import com.gec.model.system.ITripHotelRoom;
import com.gec.model.system.ITripRoomType;
import com.gec.model.system.ITripService;
import com.gec.model.vo.ITripRoomTypeVo;
import com.gec.model.vo.ITripServiceVo;
import com.gec.system.common.Result;
import com.gec.system.service.ITripHotelRoomService;
import com.gec.system.service.ITripHotelService;
import com.gec.system.service.ITripRoomTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dafei
 * @since 2024-01-24
 */
@RestController
@RequestMapping("/system/itrRoomType")
@Api(tags="房间类型管理")
@CrossOrigin
public class ITripRoomTypeController {

    @Autowired
    private ITripRoomTypeService iTripRoomTypeService;

    // 分页 + 查询
    @ApiOperation("套餐分页查询")
    @GetMapping("/{page}/{limit}")
    public Result findRoleByPageQuery(@PathVariable Long page,
                                      @PathVariable Long limit,
                                      ITripRoomTypeVo iTripRoomTypeVo)
    {
        IPage<ITripRoomType> page1 = new Page<>(page,limit);
        page1 =   this.iTripRoomTypeService.selectPage(page1,iTripRoomTypeVo);
        return Result.ok(page1);
    }

    @ApiOperation("查询全部房间类型")
    @GetMapping("/findAll")
    public Result findAll(){
        List<ITripRoomType> list = this.iTripRoomTypeService.list();
        return Result.ok(list);
    }

    @ApiOperation("根据id去移除一个角色")
    // 测试删除
    @DeleteMapping("/removeroomType/{id}")
    public Result removeHotel(@PathVariable Long id)
    {
        boolean b = this.iTripRoomTypeService.removeById(id);
        if (b){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }



    // 添加

    @PostMapping("/addHotel")
    public Result addHotel(@RequestBody ITripRoomType iTripRoomType)
    {
        //        添加编号唯一性判断
        ITripRoomType it = iTripRoomTypeService.selectByName(iTripRoomType.getRoomType());
        if (it != null) {
            return Result.fail("name重复");
        }
        boolean res = this.iTripRoomTypeService.save(iTripRoomType);
        if (res){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }
    // 修改
    @GetMapping("/findHotelById/{id}")
    public Result findHotelById(@PathVariable Long id)
    {
        ITripRoomType iTripHotel = this.iTripRoomTypeService.getById(id);
        return Result.ok(iTripHotel);
    }

    // 实现修改
    @PostMapping("/updateHotel")
    public Result updateHotel(@RequestBody ITripRoomType iTripRoomType)
    {
        boolean b = this.iTripRoomTypeService.updateById(iTripRoomType);
        if (b) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

}

